package thread08;

public class Ticket implements Runnable {
	private int ticket = 100;//初始化100张票

/*	@Override
	public synchronized void run() {
		//卖票
		while (true) {

			if (ticket > 0) {
				System.out.println(Thread.currentThread().getName() + "..." + ticket--);
			}

		}
	}*/

	/*@Override
	public void run() {
		synchronized(this) {
			//System.out.println(this);
			//卖票
			while (true) {

				if (ticket > 0) {
					System.out.println(Thread.currentThread().getName() + "..." + ticket--);
				}

			}
		}
	}*/
	public void run() {

			while (true) {

				sellTicket();

			}
	}

	private synchronized void sellTicket() {
		if (ticket > 0) {
			System.out.println(Thread.currentThread().getName() + "..." + ticket--);
		}
	}

}
